package com.example.springaopdemo.demos.web.proxy;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.InvocationHandler;
import org.springframework.cglib.proxy.Proxy;
/**
 * @author Q
 * @create 2025-06-17-9:39
 */
public class DynamicMain {
    public static void main(String[]args){
            HouseSubject target = new RealHouseSubject();
            HouseProxy proxy = (HouseProxy) Proxy.newProxyInstance(target.getClass().getClassLoader(),
                    new Class[]{HouseSubject.class}, (InvocationHandler) new JDKInvocationHandler(target));
            proxy.rent();
            proxy.sale();

        HouseSubject proxy2 = (HouseSubject) Enhancer.create(HouseSubject.class, new CGLibMethodInterceptor(target));
        proxy2.rent();
    }
}
